//#include <QGuiApplication>
//#include <QQmlApplicationEngine>


//int main(int argc, char *argv[])
//{
//#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
//    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//#endif

//    QGuiApplication app(argc, argv);

//    QQmlApplicationEngine engine;
//    const QUrl url(QStringLiteral("qrc:/main.qml"));
//    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
//                     &app, [url](QObject *obj, const QUrl &objUrl) {
//        if (!obj && url == objUrl)
//            QCoreApplication::exit(-1);
//    }, Qt::QueuedConnection);
//    engine.load(url);

//    return app.exec();
//}

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlComponent>

#include <QDebug>
#include <QObject>

#include "mainqmlhandler.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    //省略其他代码，关键代码如下：
    qmlRegisterType<MainQmlHandler>("an.qml.TransObj", 1, 0, "TransObj");

    QQmlApplicationEngine engine;

    const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);

//    QQmlComponent compont(&engine);
//    compont.loadUrl(QUrl(QString("qrc:/Window.qml")));
//    QObject *qmlWindow = compont.create();
//    qmlWindow->setParent(engine.rootObjects()[0]);
//    engine.rootContext()->setContextProperty("qmlWindows", qmlWindow);

    //QObject *rect = qmlWindow->findChild<QObject*>("textEdit");
    //rect->setProperty()

//    MainQmlHandler textEditHandler;
//    engine.rootContext()->setContextProperty("TextEditHandler", &textEditHandler);

//    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

//    QObject* root = engine.rootObjects().first();
//    //QObject *root_first;
//    QObject* textEdit = root->findChild<QObject*>("textEdit");
//    QObject::connect(textEdit, SIGNAL(textChanged(QString)),
//                     &textEditHandler, SLOT(handleTextChanged(QString)));
//    if (textEdit)
//    {

//    }

    return app.exec();
}

//#include "main.moc"
